<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
    <title>Hoodoo::Errors</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <link rel="stylesheet" href="../../css/reset.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../css/main.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../../css/github.css" type="text/css" media="screen" />
<script src="../../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
<script src="../../js/main.js" type="text/javascript" charset="utf-8"></script>
<script src="../../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>

</head>

<body>
    <div class="banner">
        <h1>
            <span class="type">Class</span>
            Hoodoo::Errors
                <span class="parent">&lt;
                    Object
                </span>
        </h1>
        <ul class="files">
            <li><a href="../../files/lib/hoodoo/errors/errors_rb.html">lib/hoodoo/errors/errors.rb</a></li>
        </ul>
    </div>
    <div id="bodyContent">
        <div id="content">
    <div class="description">
      
<p>During request processing, API service implementations create an <a
href="Errors.html">Hoodoo::Errors</a> instance and add error(s) to the
collection as they arise using <a
href="Errors.html#method-i-add_error">add_error</a>. That same instance can
then be returned for the on-error handling path of whatever wider service
framework is in use by the service code in question. <a
href="Services.html">Services</a> should use new instances for each
request.</p>

    </div>






    <!-- Namespace -->
    <div class="sectiontitle">Namespace</div>
    <ul>
        <li>
          <span class="type">CLASS</span>
          <a href="Errors/MissingReferenceData.html">Hoodoo::Errors::MissingReferenceData</a>
        </li>
        <li>
          <span class="type">CLASS</span>
          <a href="Errors/UnknownCode.html">Hoodoo::Errors::UnknownCode</a>
        </li>
    </ul>


    <!-- Method ref -->
    <div class="sectiontitle">Methods</div>
    <dl class="methods">
        <dt>A</dt>
        <dd>
          <ul>
              <li>
                <a href="#method-i-add_error">add_error</a>,
              </li>
              <li>
                <a href="#method-i-add_precompiled_error">add_precompiled_error</a>
              </li>
          </ul>
        </dd>
        <dt>C</dt>
        <dd>
          <ul>
              <li>
                <a href="#method-i-clear_errors">clear_errors</a>
              </li>
          </ul>
        </dd>
        <dt>H</dt>
        <dd>
          <ul>
              <li>
                <a href="#method-i-has_errors-3F">has_errors?</a>
              </li>
          </ul>
        </dd>
        <dt>I</dt>
        <dd>
          <ul>
              <li>
                <a href="#method-i-inspect">inspect</a>
              </li>
          </ul>
        </dd>
        <dt>M</dt>
        <dd>
          <ul>
              <li>
                <a href="#method-i-merge-21">merge!</a>
              </li>
          </ul>
        </dd>
        <dt>N</dt>
        <dd>
          <ul>
              <li>
                <a href="#method-c-new">new</a>
              </li>
          </ul>
        </dd>
        <dt>R</dt>
        <dd>
          <ul>
              <li>
                <a href="#method-i-render">render</a>
              </li>
          </ul>
        </dd>
        <dt>U</dt>
        <dd>
          <ul>
              <li>
                <a href="#method-i-unjoin_and_unescape_commas">unjoin_and_unescape_commas</a>
              </li>
          </ul>
        </dd>
    </dl>







      <!-- Section constants -->
      <div class="sectiontitle">Constants</div>
      <table border='0' cellpadding='5'>
          <tr valign='top' id='DEFAULT_ERROR_DESCRIPTIONS'>
            <td class="attr-name">DEFAULT_ERROR_DESCRIPTIONS</td>
            <td>=</td>
            <td class="attr-value"><pre>Hoodoo::ErrorDescriptions.new()</pre></td>
          </tr>
            <tr valign='top'>
              <td>&nbsp;</td>
              <td colspan="2" class="attr-desc"><p>Default <a href="ErrorDescriptions.html">Hoodoo::ErrorDescriptions</a>
instance, used if the instantiator provides no alternative.</p></td>
            </tr>
      </table>

      <!-- Section attributes -->
      <div class="sectiontitle">Attributes</div>
      <table border='0' cellpadding='5'>
          <tr valign='top' id='attribute-i-descriptions'>
            <td class='attr-rw'>
              [R]
            </td>
            <td class='attr-name'>descriptions</td>
            <td class='attr-desc'><p>The <a href="ErrorDescriptions.html">Hoodoo::ErrorDescriptions</a> instance
associated with this error collection. Only error codes that the
instance&#39;s <a
href="ErrorDescriptions.html#method-i-recognised-3F">Hoodoo::ErrorDescriptions#recognised?</a>
method says are recognised can be added to the error collection, else <a
href="Errors/UnknownCode.html">Hoodoo::Errors::UnknownCode</a> will be
raised.</p></td>
          </tr>
          <tr valign='top' id='attribute-i-errors'>
            <td class='attr-rw'>
              [R]
            </td>
            <td class='attr-name'>errors</td>
            <td class='attr-desc'><p>Array of error data - hashes with <code>code</code>, <code>message</code>
and <code>reference</code> fields giving the error codes, human-readable
messages and machine-readable reference data, where appropriate.</p></td>
          </tr>
          <tr valign='top' id='attribute-i-http_status_code'>
            <td class='attr-rw'>
              [R]
            </td>
            <td class='attr-name'>http_status_code</td>
            <td class='attr-desc'><p>HTTP status code associated with the first error in the <a
href="Errors.html#attribute-i-errors">errors</a> array, _as an Integer_.</p></td>
          </tr>
          <tr valign='top' id='attribute-i-uuid'>
            <td class='attr-rw'>
              [R]
            </td>
            <td class='attr-name'>uuid</td>
            <td class='attr-desc'><p><a href="Errors.html">Errors</a> are manifestations of the <a
href="Errors.html">Errors</a> resource. They acquire a <a
href="UUID.html">UUID</a> when instantiated, even if the instance is never
used or persisted.</p></td>
          </tr>
      </table>


    <!-- Methods -->
      <div class="sectiontitle">Class Public methods</div>
        <div class="method">
          <div class="title method-title" id="method-c-new">
              <b>new</b>( descriptions = DEFAULT_ERROR_DESCRIPTIONS )
            <a href="../../classes/Hoodoo/Errors.html#method-c-new" name="method-c-new" class="permalink">Link</a>
          </div>

            <div class="description">
              <p>Create an instance.</p>
<dl class="rdoc-list note-list"><dt>descriptions
<dd>
<p>(Optional) <a href="ErrorDescriptions.html">Hoodoo::ErrorDescriptions</a>
instance with service-domain-specific error descriptions added, or omit for
a default instance describing <code>platform</code> and
<code>generic</code> error domains only.</p>
</dd></dl>
            </div>



            <div class="sourcecode">
              <p class="source-link">
                Source:
                <a href="javascript:toggleSource('method-c-new_source')" id="l_method-c-new_source">show</a>
              </p>
              <div id="method-c-new_source" class="dyn-source">
                <pre><span class="ruby-comment"># File lib/hoodoo/errors/errors.rb, line 71</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">initialize</span>( <span class="ruby-identifier">descriptions</span> = <span class="ruby-constant">DEFAULT_ERROR_DESCRIPTIONS</span> )
  <span class="ruby-ivar">@uuid</span>             = <span class="ruby-constant">Hoodoo</span><span class="ruby-operator">::</span><span class="ruby-constant">UUID</span>.<span class="ruby-identifier">generate</span>()
  <span class="ruby-ivar">@descriptions</span>     = <span class="ruby-identifier">descriptions</span>
  <span class="ruby-ivar">@errors</span>           = []
  <span class="ruby-ivar">@http_status_code</span> = <span class="ruby-number">200</span>
  <span class="ruby-ivar">@created_at</span>       = <span class="ruby-keyword">nil</span> <span class="ruby-comment"># See #persist!</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
          </div>
      <div class="sectiontitle">Instance Public methods</div>
        <div class="method">
          <div class="title method-title" id="method-i-add_error">
              <b>add_error</b>( code, options = nil )
            <a href="../../classes/Hoodoo/Errors.html#method-i-add_error" name="method-i-add_error" class="permalink">Link</a>
          </div>

            <div class="description">
              <p>Add an error instance to this collection.</p>
<dl class="rdoc-list note-list"><dt>code
<dd>
<p>Error code in full, e.g. +generic.invalid_state&#39;.</p>
</dd><dt>options
<dd>
<p>An options Hash, optional.</p>
</dd></dl>

<p>The options hash contains symbol keys named as follows, with values as
described:</p>
<dl class="rdoc-list note-list"><dt><code>reference</code>
<dd>
<p>Reference data Hash, optionality depending upon the error code and the
reference data its error description mandates. Provide key/value pairs
where (symbol) keys are names from the array of description requirements
and values are strings. All values are concatenated into a single string,
comma-separated. Commas within values are escaped with a backslash;
backslash is itself escaped with a backslash.</p>

<p>You must provide that data at a minimum, but can provide additional keys
too if you so wish. Required keys are always included first, in order of
appearance in the requirements array of the error declaration, followed by
any extra values in undefined order.</p>

<p>See also <a
href="ErrorDescriptions/DomainDescriptions.html#method-i-error">Hoodoo::ErrorDescriptions::DomainDescriptions#error</a></p>
</dd><dt><code>message</code>
<dd>
<p>Optional human-readable for-developer message, <code>en-nz</code> locale.
Default messages are provided for all errors, but if you think you can
provide something more informative, you can do so through this parameter.</p>
</dd></dl>

<p>Example:</p>

<pre><code>errors.add_error(
  &#39;platform.not_found&#39;,
  :message =&gt; &#39;Optional custom message&#39;,
  :reference =&gt; { :entity_name =&gt; &#39;mandatory reference data&#39; }
)
</code></pre>

<p>In the above example, the mandatory reference data <code>entity_name</code>
comes from the description for the &#39;platform.not_found&#39; message -
see the Hoodoo::ErrorDescriptions#initialize <em>implementation</em> and
Platform API.</p>
            </div>



            <div class="sourcecode">
              <p class="source-link">
                Source:
                <a href="javascript:toggleSource('method-i-add_error_source')" id="l_method-i-add_error_source">show</a>
              </p>
              <div id="method-i-add_error_source" class="dyn-source">
                <pre><span class="ruby-comment"># File lib/hoodoo/errors/errors.rb, line 121</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">add_error</span>( <span class="ruby-identifier">code</span>, <span class="ruby-identifier">options</span> = <span class="ruby-keyword">nil</span> )

  <span class="ruby-identifier">options</span>   = <span class="ruby-constant">Hoodoo</span><span class="ruby-operator">::</span><span class="ruby-constant">Utilities</span>.<span class="ruby-identifier">stringify</span>( <span class="ruby-identifier">options</span> <span class="ruby-operator">||</span> {} )
  <span class="ruby-identifier">reference</span> = <span class="ruby-identifier">options</span>[ <span class="ruby-string">&#39;reference&#39;</span> ] <span class="ruby-operator">||</span> {}
  <span class="ruby-identifier">message</span>   = <span class="ruby-identifier">options</span>[ <span class="ruby-string">&#39;message&#39;</span> ]

  <span class="ruby-comment"># Make sure nobody uses an undeclared error code.</span>

  <span class="ruby-identifier">raise</span> <span class="ruby-constant">UnknownCode</span>, <span class="ruby-node">&quot;In \#add_error: Unknown error code &#39;#{code}&#39;&quot;</span> <span class="ruby-keyword">unless</span> <span class="ruby-ivar">@descriptions</span>.<span class="ruby-identifier">recognised?</span>( <span class="ruby-identifier">code</span> )

  <span class="ruby-comment"># If the error description specifies a list of required reference keys,</span>
  <span class="ruby-comment"># make sure all are present and complain if not.</span>

  <span class="ruby-identifier">description</span> = <span class="ruby-ivar">@descriptions</span>.<span class="ruby-identifier">describe</span>( <span class="ruby-identifier">code</span> )

  <span class="ruby-identifier">required_keys</span> = <span class="ruby-identifier">description</span>[ <span class="ruby-string">&#39;reference&#39;</span> ] <span class="ruby-operator">||</span> []
  <span class="ruby-identifier">actual_keys</span>   = <span class="ruby-identifier">reference</span>.<span class="ruby-identifier">keys</span>
  <span class="ruby-identifier">missing_keys</span>  = <span class="ruby-identifier">required_keys</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">actual_keys</span>

  <span class="ruby-keyword">unless</span> <span class="ruby-identifier">missing_keys</span>.<span class="ruby-identifier">empty?</span>
    <span class="ruby-identifier">raise</span> <span class="ruby-constant">MissingReferenceData</span>, <span class="ruby-node">&quot;In \#add_error: Reference hash missing required keys: &#39;#{ missing_keys.join( &#39;, &#39; ) }&#39;&quot;</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-comment"># All good!</span>

  <span class="ruby-ivar">@http_status_code</span> = ( <span class="ruby-identifier">description</span>[ <span class="ruby-string">&#39;status&#39;</span> ] <span class="ruby-operator">||</span> <span class="ruby-number">200</span> ).<span class="ruby-identifier">to_i</span> <span class="ruby-keyword">if</span> <span class="ruby-ivar">@errors</span>.<span class="ruby-identifier">empty?</span> <span class="ruby-comment"># Use first in collection for overall HTTP status code</span>

  <span class="ruby-identifier">error</span> = {
    <span class="ruby-string">&#39;code&#39;</span>    =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">code</span>,
    <span class="ruby-string">&#39;message&#39;</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">message</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">description</span>[ <span class="ruby-string">&#39;message&#39;</span> ] <span class="ruby-operator">||</span> <span class="ruby-identifier">code</span>
  }

  <span class="ruby-identifier">ordered_keys</span>   = <span class="ruby-identifier">required_keys</span> <span class="ruby-operator">+</span> ( <span class="ruby-identifier">actual_keys</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">required_keys</span> )
  <span class="ruby-identifier">ordered_values</span> = <span class="ruby-identifier">ordered_keys</span>.<span class="ruby-identifier">map</span> { <span class="ruby-operator">|</span> <span class="ruby-identifier">key</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">escape_commas</span>( <span class="ruby-identifier">reference</span>[ <span class="ruby-identifier">key</span> ].<span class="ruby-identifier">to_s</span> ) }

  <span class="ruby-comment"># See #unjoin_and_unescape_commas to undo the join below.</span>

  <span class="ruby-identifier">error</span>[ <span class="ruby-string">&#39;reference&#39;</span> ] = <span class="ruby-identifier">ordered_values</span>.<span class="ruby-identifier">join</span>( <span class="ruby-string">&#39;,&#39;</span> ) <span class="ruby-keyword">unless</span> <span class="ruby-identifier">ordered_values</span>.<span class="ruby-identifier">empty?</span>

  <span class="ruby-ivar">@errors</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">error</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
          </div>
        <div class="method">
          <div class="title method-title" id="method-i-add_precompiled_error">
              <b>add_precompiled_error</b>( code, message, reference, http_status = 500 )
            <a href="../../classes/Hoodoo/Errors.html#method-i-add_precompiled_error" name="method-i-add_precompiled_error" class="permalink">Link</a>
          </div>

            <div class="description">
              <p>Add a precompiled error to the error collection. Pass error code, error
message and reference data directly.</p>

<p>In most cases you should be calling <a
href="Errors.html#method-i-add_error">add_error</a> instead,
<strong>NOT</strong> here.</p>

<p><strong>No</strong> <strong>validation</strong> is performed. You should
only really call here if storing an error / errors from another, trusted
source with assumed validity (e.g. another service called remotely with
errors in the JSON response). It&#39;s possible to store invalid error data
using this call, which means counter-to-documentation results could be
returned to API clients. That is Very Bad.</p>

<p>Pass optionally the HTTP status code to use if this happens to be the first
stored error. If this is omitted, 500 is kept as the default.</p>
            </div>



            <div class="sourcecode">
              <p class="source-link">
                Source:
                <a href="javascript:toggleSource('method-i-add_precompiled_error_source')" id="l_method-i-add_precompiled_error_source">show</a>
              </p>
              <div id="method-i-add_precompiled_error_source" class="dyn-source">
                <pre><span class="ruby-comment"># File lib/hoodoo/errors/errors.rb, line 178</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">add_precompiled_error</span>( <span class="ruby-identifier">code</span>, <span class="ruby-identifier">message</span>, <span class="ruby-identifier">reference</span>, <span class="ruby-identifier">http_status</span> = <span class="ruby-number">500</span> )
  <span class="ruby-ivar">@http_status_code</span> = <span class="ruby-identifier">http_status</span>.<span class="ruby-identifier">to_i</span> <span class="ruby-keyword">if</span> <span class="ruby-ivar">@errors</span>.<span class="ruby-identifier">empty?</span>

  <span class="ruby-identifier">error</span> = {
    <span class="ruby-string">&#39;code&#39;</span>    =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">code</span>,
    <span class="ruby-string">&#39;message&#39;</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">message</span>
  }

  <span class="ruby-identifier">error</span>[ <span class="ruby-string">&#39;reference&#39;</span> ] = <span class="ruby-identifier">reference</span> <span class="ruby-keyword">unless</span> <span class="ruby-identifier">reference</span>.<span class="ruby-identifier">nil?</span> <span class="ruby-operator">||</span> <span class="ruby-identifier">reference</span>.<span class="ruby-identifier">empty?</span>

  <span class="ruby-ivar">@errors</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">error</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
          </div>
        <div class="method">
          <div class="title method-title" id="method-i-clear_errors">
              <b>clear_errors</b>()
            <a href="../../classes/Hoodoo/Errors.html#method-i-clear_errors" name="method-i-clear_errors" class="permalink">Link</a>
          </div>

            <div class="description">
              <p>Clear (delete) all previously added errors (if any). After calling here, <a
href="Errors.html#method-i-has_errors-3F">has_errors?</a> would always
return <code>false</code>.</p>
            </div>



            <div class="sourcecode">
              <p class="source-link">
                Source:
                <a href="javascript:toggleSource('method-i-clear_errors_source')" id="l_method-i-clear_errors_source">show</a>
              </p>
              <div id="method-i-clear_errors_source" class="dyn-source">
                <pre><span class="ruby-comment"># File lib/hoodoo/errors/errors.rb, line 227</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">clear_errors</span>
  <span class="ruby-ivar">@errors</span>           = []
  <span class="ruby-ivar">@http_status_code</span> = <span class="ruby-number">200</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
          </div>
        <div class="method">
          <div class="title method-title" id="method-i-has_errors-3F">
              <b>has_errors?</b>()
            <a href="../../classes/Hoodoo/Errors.html#method-i-has_errors-3F" name="method-i-has_errors-3F" class="permalink">Link</a>
          </div>

            <div class="description">
              <p>Does this instance have any errors added? Returns <code>true</code> if so,
else <code>false</code>.</p>
            </div>



            <div class="sourcecode">
              <p class="source-link">
                Source:
                <a href="javascript:toggleSource('method-i-has_errors-3F_source')" id="l_method-i-has_errors-3F_source">show</a>
              </p>
              <div id="method-i-has_errors-3F_source" class="dyn-source">
                <pre><span class="ruby-comment"># File lib/hoodoo/errors/errors.rb, line 220</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">has_errors?</span>
  <span class="ruby-operator">!</span> <span class="ruby-ivar">@errors</span>.<span class="ruby-identifier">empty?</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
          </div>
        <div class="method">
          <div class="title method-title" id="method-i-inspect">
              <b>inspect</b>()
            <a href="../../classes/Hoodoo/Errors.html#method-i-inspect" name="method-i-inspect" class="permalink">Link</a>
          </div>

            <div class="description">
              <p>Make life easier for debugging on the console by having the object
represent itself more concisely.</p>
            </div>



            <div class="sourcecode">
              <p class="source-link">
                Source:
                <a href="javascript:toggleSource('method-i-inspect_source')" id="l_method-i-inspect_source">show</a>
              </p>
              <div id="method-i-inspect_source" class="dyn-source">
                <pre><span class="ruby-comment"># File lib/hoodoo/errors/errors.rb, line 258</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">inspect</span>
  <span class="ruby-ivar">@errors</span>.<span class="ruby-identifier">to_s</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
          </div>
        <div class="method">
          <div class="title method-title" id="method-i-merge-21">
              <b>merge!</b>( source )
            <a href="../../classes/Hoodoo/Errors.html#method-i-merge-21" name="method-i-merge-21" class="permalink">Link</a>
          </div>

            <div class="description">
              <p>Merge the contents of a source error object with this one, adding its
errors to this collection. No checks are made for duplicates (in part
because, depending on error code and source/target contexts, a duplicate
may be a valid thing to have).</p>
<dl class="rdoc-list note-list"><dt><code>source</code>
<dd>
<p><a href="Errors.html">Hoodoo::Errors</a> instance to merge into the error
collection of &#39;this&#39; target object.</p>
</dd></dl>

<p>Returns <code>true</code> if errors were merged, else <code>false</code>
(the source collection was empty).</p>
            </div>



            <div class="sourcecode">
              <p class="source-link">
                Source:
                <a href="javascript:toggleSource('method-i-merge-21_source')" id="l_method-i-merge-21_source">show</a>
              </p>
              <div id="method-i-merge-21_source" class="dyn-source">
                <pre><span class="ruby-comment"># File lib/hoodoo/errors/errors.rb, line 202</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">merge!</span>( <span class="ruby-identifier">source</span> )
  <span class="ruby-identifier">source_errors</span> = <span class="ruby-identifier">source</span>.<span class="ruby-identifier">errors</span>

  <span class="ruby-identifier">source_errors</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">hash</span> <span class="ruby-operator">|</span>
    <span class="ruby-identifier">add_precompiled_error</span>(
      <span class="ruby-identifier">hash</span>[ <span class="ruby-string">&#39;code&#39;</span>      ],
      <span class="ruby-identifier">hash</span>[ <span class="ruby-string">&#39;message&#39;</span>   ],
      <span class="ruby-identifier">hash</span>[ <span class="ruby-string">&#39;reference&#39;</span> ],
      <span class="ruby-identifier">source</span>.<span class="ruby-identifier">http_status_code</span>
    )
  <span class="ruby-keyword">end</span>

  <span class="ruby-keyword">return</span> <span class="ruby-operator">!</span> <span class="ruby-identifier">source_errors</span>.<span class="ruby-identifier">empty?</span>
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
          </div>
        <div class="method">
          <div class="title method-title" id="method-i-render">
              <b>render</b>( interaction_id )
            <a href="../../classes/Hoodoo/Errors.html#method-i-render" name="method-i-render" class="permalink">Link</a>
          </div>

            <div class="description">
              <p>Return a Hash rendered through the <a
href="Data/Resources/Errors.html">Hoodoo::Data::Resources::Errors</a>
collection representing the formalised resource.</p>
<dl class="rdoc-list note-list"><dt><code>interaction_id</code>
<dd>
<p>Mandatory Interaction ID (UUID) to associate with the collection.</p>
</dd></dl>
            </div>



            <div class="sourcecode">
              <p class="source-link">
                Source:
                <a href="javascript:toggleSource('method-i-render_source')" id="l_method-i-render_source">show</a>
              </p>
              <div id="method-i-render_source" class="dyn-source">
                <pre><span class="ruby-comment"># File lib/hoodoo/errors/errors.rb, line 238</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">render</span>( <span class="ruby-identifier">interaction_id</span> )
  <span class="ruby-keyword">unless</span> <span class="ruby-constant">Hoodoo</span><span class="ruby-operator">::</span><span class="ruby-constant">UUID</span>.<span class="ruby-identifier">valid?</span>( <span class="ruby-identifier">interaction_id</span> )
    <span class="ruby-identifier">raise</span> <span class="ruby-node">&quot;Hoodoo::Errors\#render must be given a valid Interaction ID (got &#39;#{ interaction_id.inspect }&#39;)&quot;</span>
  <span class="ruby-keyword">end</span>

  <span class="ruby-ivar">@created_at</span> <span class="ruby-operator">||=</span> <span class="ruby-constant">Time</span>.<span class="ruby-identifier">now</span>

  <span class="ruby-constant">Hoodoo</span><span class="ruby-operator">::</span><span class="ruby-constant">Data</span><span class="ruby-operator">::</span><span class="ruby-constant">Resources</span><span class="ruby-operator">::</span><span class="ruby-constant">Errors</span>.<span class="ruby-identifier">render</span>(
    {
      <span class="ruby-string">&#39;interaction_id&#39;</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">interaction_id</span>,
      <span class="ruby-string">&#39;errors&#39;</span>         =<span class="ruby-operator">&gt;</span> <span class="ruby-ivar">@errors</span>
    },
    <span class="ruby-ivar">@uuid</span>,
    <span class="ruby-ivar">@created_at</span>
  )
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
          </div>
        <div class="method">
          <div class="title method-title" id="method-i-unjoin_and_unescape_commas">
              <b>unjoin_and_unescape_commas</b>( str )
            <a href="../../classes/Hoodoo/Errors.html#method-i-unjoin_and_unescape_commas" name="method-i-unjoin_and_unescape_commas" class="permalink">Link</a>
          </div>

            <div class="description">
              <p>When reference data is specified for errors, the reference values are
concatenated together into a comma-separated string. Since reference values
can themselves contain commas, comma is escaped with “\,” and “\” escaped
with “\\”.</p>

<p>Call here with such a string; return an array of &#39;unescaped&#39;
values.</p>
<dl class="rdoc-list note-list"><dt><code>str</code>
<dd>
<p>Value-escaped (“\\” / “\,”) comma-separated string. Unescaped commas
separate individual values.</p>
</dd></dl>
            </div>



            <div class="sourcecode">
              <p class="source-link">
                Source:
                <a href="javascript:toggleSource('method-i-unjoin_and_unescape_commas_source')" id="l_method-i-unjoin_and_unescape_commas_source">show</a>
              </p>
              <div id="method-i-unjoin_and_unescape_commas_source" class="dyn-source">
                <pre><span class="ruby-comment"># File lib/hoodoo/errors/errors.rb, line 278</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">unjoin_and_unescape_commas</span>( <span class="ruby-identifier">str</span> )

  <span class="ruby-comment"># In Ruby regular expressions, &#39;(?&lt;!pat)&#39; is a negative lookbehind</span>
  <span class="ruby-comment"># assertion, making sure that the preceding characters do not match</span>
  <span class="ruby-comment"># &#39;pat&#39;. To split the string joined on &#39;,&#39; to an array but not splitting</span>
  <span class="ruby-comment"># any escaped &#39;\,&#39;, then, we can use this rather opaque split regexp:</span>
  <span class="ruby-comment">#</span>
  <span class="ruby-comment">#   error[ &#39;reference&#39; ].split( /(?&lt;!\\),/ )</span>
  <span class="ruby-comment">#</span>
  <span class="ruby-comment"># I.e. split on &#39;,&#39;, provided it is not preceded by a &#39;\&#39; (escaped in the</span>
  <span class="ruby-comment"># regexp to &#39;\\&#39;).</span>

  <span class="ruby-identifier">ary</span> = <span class="ruby-identifier">str</span>.<span class="ruby-identifier">split</span>( <span class="ruby-regexp">/(?&lt;!\),/</span> )
  <span class="ruby-identifier">ary</span>.<span class="ruby-identifier">map</span> { <span class="ruby-operator">|</span> <span class="ruby-identifier">entry</span> <span class="ruby-operator">|</span> <span class="ruby-identifier">unescape_commas</span>( <span class="ruby-identifier">entry</span> ) }
<span class="ruby-keyword">end</span></pre>
              </div>
            </div>
          </div>
</div>

    </div>
  </body>
</html>
